import "package:flutter/material.dart";
import 'package:word_range_client/pages/general/Exercise.dart';
import 'package:word_range_client/widgets/home/BookButton.dart';
// 组件
import 'package:word_range_client/widgets/home/Greetings.dart';
import 'package:word_range_client/widgets/home/StartButton.dart';
import 'package:word_range_client/widgets/home/WeekImg.dart';
import 'package:word_range_client/widgets/home/WordOfDay.dart';

import '../../widgets/home/RevisionPlanSettingButton.dart';


/// 手机端主页
class PhoneHome extends StatefulWidget {
  const PhoneHome({super.key});

  @override
  State<PhoneHome> createState() => _PhoneHomeState();
}

class _PhoneHomeState extends State<PhoneHome> {

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  void toPracticePage(){
    Navigator.of(context).push(
        MaterialPageRoute(
            builder: (context) => const Exercise()
        )
    );
  }

  void _onBookChanged() {
    setState(() {});  // 回调setState()强制重载元素
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: StartButton(onPressed: toPracticePage,),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      body: Padding(
        padding: const EdgeInsets.all(25),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        const Greetings(),
                        Row(
                          children: [
                            BookButton(onBookChanged: _onBookChanged,),
                            const SizedBox(width: 5,),
                            const RevisionPlanSettingButton(),
                          ],
                        )
                      ],
                    ),
                    const WeekImg()
                  ],
                ),
                const _PartingLine()
              ],
            ),
            const SizedBox(),
            const WordOfDay(),
            const SizedBox(height: 90,),
          ],
        ),
      ),
    );
  }
}

class _PartingLine extends StatelessWidget {
  const _PartingLine({super.key});

  @override
  Widget build(BuildContext context) {
    return const SizedBox(
      height: 20,
      child: Divider(
        height: 1.0,
        color: Colors.black38,
      ),
    );
  }
}

